﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Configuration;

public partial class MasterPages_Privada : System.Web.UI.MasterPage
{
    protected void Page_Load(object sender, EventArgs e)
    {
        Boolean autenticado = false;
        if (Session[ConfigurationManager.AppSettings["autenticado"]] != null)
        {
            LiteralFecha.Text = DateTime.Now.ToLongDateString();
            if (!HttpContext.Current.Request.Url.ToString().EndsWith(".aspx"))
            {
                if (!HttpContext.Current.Request.Url.LocalPath.EndsWith("Objeto.aspx"))
                {
                    Response.Redirect(ConfigurationManager.AppSettings["PaginaDeInicio"]);
                }
            }
            autenticado = (Boolean)Session[ConfigurationManager.AppSettings["autenticado"]];
        }

        if (!autenticado)
        {
            salir();
        }
        else
        {
            Int32 perfil;
            Int32.TryParse(Session[ConfigurationManager.AppSettings["perfilUsuario"]].ToString(), out perfil);
        }
    }

    protected void LinkButtonSalir_Click(object sender, EventArgs e)
    {
        Session[ConfigurationManager.AppSettings["idUsuario"]] = null;
        Session[ConfigurationManager.AppSettings["nombreUsuario"]] = null;
        Session[ConfigurationManager.AppSettings["claveUsuario"]] = null;
        Session[ConfigurationManager.AppSettings["perfilUsuario"]] = null;
        Session[ConfigurationManager.AppSettings["autenticado"]] = null;
        salir();
    }

    private void salir()
    {
        Response.Redirect(ConfigurationManager.AppSettings["PaginaDeLogin"]);
    }
}
